package com.szqhyxj.youxiangju.biz.merchantHome.shop.commoditeDetails;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.szqhyxj.youxiangju.BaseActivity;
import com.szqhyxj.youxiangju.R;
import com.szqhyxj.youxiangju.biz.merchantHome.bean.CommoditeDetails;
import com.szqhyxj.youxiangju.biz.merchantHome.shop.purchase.PreparePurchaseActivity;
import com.szqhyxj.youxiangju.sys.components.LoadImageUtils;
import com.szqhyxj.youxiangju.sys.components.NavigationBar;
import com.szqhyxj.youxiangju.sys.util.StringUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 商品设备详情
 */
public class CommoditeDeviceDetailsActivity extends BaseActivity implements CommoditeDetailsContract.View, NavigationBar.NavigationBarListener{

    private static String PACKAGEID = "packageId";

    @BindView(R.id.navigationBar)
    NavigationBar navigationBar;
    @BindView(R.id.icon)
    ImageView icon;
    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.content_service)
    TextView contentService;
    @BindView(R.id.type)
    TextView type;

    @BindView(R.id.save)
    Button save;
    @BindView(R.id.price)
    TextView price;
    @BindView(R.id.quantity)
    TextView quantity;
    private CommoditeDetailsPresenter presenter;

    public static void start(Activity activity, String packageId){
        Intent intent = new Intent();
        intent.setClass(activity, CommoditeDeviceDetailsActivity.class);
        intent.putExtra(PACKAGEID, packageId);
        activity.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_commodite_device_details);
        ButterKnife.bind(this);
        String packageId = getIntent().getStringExtra(PACKAGEID);
        presenter = new CommoditeDetailsPresenter(this);
        presenter.init(packageId);

        navigationBar.setNavigationBarListener(this);

        initViews();
    }

    private void initViews(){

       StringUtils.setColorText(contentService,getResources().getColor(R.color.colorTextGrayHint)
               ,getResources().getString(R.string.warm_prompt_02)
               ,getResources().getColor(R.color.colorTextBlue)
               ,"400-843-3388");

    }

    @OnClick({R.id.save})
    public void onViewClicked(View view){
        switch(view.getId()){
            case R.id.save:
                presenter.save();
                break;

        }
    }

    @Override
    public void showCommodite(CommoditeDetails data){
        LoadImageUtils.loadImage(icon, data.getBigPic());
        title.setText(data.getPackageName());
        quantity.setText("/"+data.getDeviceNum()+"台");
        price.setText(StringUtils.initPrice(data.getPackagePrice()));
        type.setText(data.getBrandName());
    }

    @Override
    public void navPurchase(CommoditeDetails details){
        PreparePurchaseActivity.start(this,details);
    }

    @Override
    public void navigationLeft(){
        finish();
    }

    @Override
    public void navigationRight(){
    }
}
